/*
 *  SmtpPseudocode.h
 *  MinimalSmtp
 *
 *  Created by Andrey on 22/12/2008.
 *  Copyright 2008 Karma Software. All rights reserved.
 *
 */

#ifndef SMTP_PSEUDOCODE
#define SMTP_PSEUDOCODE

#define TRANSITION_HANDLER_START(handler) \
void handler(enum SmtpEvent ev, enum SmtpState old_state, void *ctx)\
{\
	CDClientInfoPtr clientInfo = (CDClientInfoPtr)ctx;\
	SmtpEnvelopePtr smtpEnvelope = (SmtpEnvelopePtr)clientInfo->clientData;\
	SmtpCommandHeaderPtr header = clientInfo->currentCommandHeader; \
	SmtpCommandWithAddressPtr currentCommand = HEADER_TO_COMMAND(header, SmtpCommandWithAddress);\

#define TRANSITION_HANDLER_END }

#define previousState old_state
#define event ev

#define CopyMailboxAddress(from, to) strncpy(to.localPart, from.localPart, MAX_USERNAME_LENGTH); \
					strncpy(to.domain, from.domain, MAX_DOMAIN_LENGTH)

#define ResetBuffers ((SmtpEnvelopePtr)clientInfo->clientData)->messageContents.currentOffset = 0;\
					((SmtpEnvelopePtr)clientInfo->clientData)->recipientCount = 0

#define SendReply(replyCode) WriteSmtpReplyToBuffer(clientInfo->dataToSend, replyCode)

#define StoreSender CopyMailboxAddress(currentCommand->address, smtpEnvelope->sender)

#define StoreRecipient CopyMailboxAddress(currentCommand->address, smtpEnvelope->recipients[smtpEnvelope->recipientCount]);\
					smtpEnvelope->recipientCount++

#define StoreMessageLine WriteToDataBuffer(&smtpEnvelope->messageContents, clientInfo->recentlyReceived.data, clientInfo->recentlyReceived.dataLength); 

#define StoreEnvelope MaildirStoreMessage(smtpEnvelope)

#define CloseConnection NTCloseConnection(clientInfo->clientAddress);

#endif